<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%--
  Created by IntelliJ IDEA.
  User: 张勇
  Date: 2018/3/14
  Time: 11:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="css/mystyle.css" type="text/css">
    <!-- Bootstrap CSS -->
    <!--<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">-->
    <link rel="stylesheet" href="css/bootstrap.css"/>
    <title>创建美食课堂</title>
</head>
<body>
<header>
    <nav class="navbar navbar-expand-md fixed-top navbar-dark bg-dark">
        <a class="navbar-brand" href="javascript:void(0);"><img src="<s:url value="/image/logo1.png"/>" alt="logo"
                                                                style="width:40px;"></a>
        <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse"
                aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarCollapse">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item active">
                    <a class="nav-link" href="<s:url value="/home"/>">首页 <span class="sr-only">(current)</span></a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="<s:url value="/class"/>">美食课堂</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="<s:url value="/location"/> ">同城美食</a>
                </li>
            </ul>
            <form class="form-inline mt-2 mt-md-0">
                <input class="form-control mr-sm-2" type="text" placeholder="搜索" aria-label="Search">
                <button class="btn btn-outline-success my-2 my-sm-0" type="submit">搜索</button>
            </form>

            <div id="signin" class="nav-item" style="margin-left: 10px">
                <a href="<s:url value="/login"/> " class="nav-link">登录</a>
            </div>
            <span id="split" class="navbar-text">|</span>
            <div id="signup" class="nav-item">
                <a href="<s:url value="/regist"/> " class="nav-link">注册</a>
            </div>
            <div id="usercontrol" class="nav-item dropdown ">
                <a class="nav-link dropdown-toggle navbar-brand" data-toggle="dropdown" href="#">
                    <img class="img-circle" src="<s:url value="/image/userimage.png"/>" style="width: 40px;"/>
                </a>
                <div class="dropdown-menu">
                    <a class="dropdown-item" href="<s:url value="/userpage"/>">个人主页</a>
                    <a class="dropdown-item" href="<s:url value="/createstate"/>">创建动态</a>
                    <a class="dropdown-item" href="<s:url value="/set"/>">设置</a>
                    <a class="dropdown-item" href="<s:url value="/loginout"/>">退出</a>
                </div>
            </div>
        </div>
    </nav>
</header>
<div class="container" style="margin-top:50px ">
    <img src="image/foodshare.png" class="img-fluid"/>
    <div class="card mx-auto" style="margin-top: 50px">

        <form action="createfoodschool" method="post" class="card-body w-50" enctype="multipart/form-data">
            <h5>创建课堂</h5>
            <div class="input-group mb-3 form-group">
                <div class="input-group-prepend">
                    <span class="input-group-text" id="footschoolname">课堂名：</span>
                </div>
                <input type="text" class="form-control" placeholder="课堂名" aria-describedby="footschoolname"
                       name="foodSchoolName"/>
            </div>

            <textarea class="form-control form-group" rows="4" placeholder="课堂简介"
                      name="foodMess"></textarea>

            <div class="input-group mb-3 form-group">
                <div class="input-group-prepend">
                    <span class="input-group-text" id="footschoolimg">课堂首图：</span>
                </div>
                <a href="javascript:void(0);" class="file form-control">选择图片
                    <input type="file" name="schoolImg" id="upimg">
                </a>

            </div>
            <div id="showimg"></div>
            <input type="submit" class="btn btn-primary" value="创建课堂"/>

        </form>
    </div>

</div>

<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="js/jquery-3.3.1.js"/>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.slim.min.js"
        integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN"
        crossorigin="anonymous"></script>
<script src="https://cdn.bootcss.com/popper.js/1.12.9/umd/popper.min.js"
        integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q"
        crossorigin="anonymous"></script>
<script src="https://cdn.bootcss.com/bootstrap/4.0.0/js/bootstrap.min.js"
        integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
        crossorigin="anonymous"></script>

<script type="text/javascript">
    $(document).ready(function () {


        var islogined =<%=session.getAttribute("islogined")%>;

        if (islogined == null) {
            islogined = false;
        }
        console.log("用户是否登录：" + islogined);
        if (islogined) {  //用户已经登录
            //var signin=document.getElementById("signin");
            $("#signin").hide();
            $("#signup").hide();
            $("#split").hide();
            $("#usercontrol").show();

            $("#username").text("<%=session.getAttribute("username")%>");
        } else {
            $("#signin").show();
            $("#signup").show();
            $("#split").show();
            $("#usercontrol").hide();
            $("#username").text("登录后，方可看见更加博大的美食世界");
        }

        var upimg = document.querySelector('#upimg');
        upimg.addEventListener('change', function (e) {
            var files = this.files;
            if (files.length) {
                // 对文件进行处理，下面会讲解checkFile()会做什么
                checkFile(this.files);
            }
        });

        // 图片处理
        function checkFile(files) {
            var file = files[0];
            var reader = new FileReader();
            // show表示<div id='show'></div>，用来展示图片预览的
            var show = document.querySelector('#showimg');
            if (!/image\/\w+/.test(file.type)) {
                show.innerHTML = "请确保文件为图像类型";
                return false;
            }
            // onload是异步操作
            reader.onload = function (e) {
                show.innerHTML = '<img src="' + e.target.result + '" alt="img" class="img-fluid img-thumbnail" style="width: 150px;height: 150px">';
            }
            reader.readAsDataURL(file);
        }

    });
</script>

</body>
</html>
